home *** CD-ROM | disk | FTP | other *** search
- (*************************************************************************
-
- $RCSfile: GadToolsMenu.mod $
- Description: Example illustrating the use of GadTools menus.
-
- Created by: fjc (Frank Copeland)
- $Revision: 1.5 $
- $Author: fjc $
- $Date: 1995/01/25 23:49:09 $
-
- Copyright © 1994-1995, Frank Copeland.
- This example program is part of Oberon-A.
- See Oberon-A.doc for conditions of use and distribution.
-
- *************************************************************************)
-
- <* STANDARD- *>
-
- MODULE GadToolsMenu;
-
- IMPORT
- SYS := SYSTEM,
- e := Exec,
- u := Utility,
- i := Intuition,
- gt := GadTools;
-
- CONST
- VersionTag = "$VER: GadToolsMenu 1.2 (23.1.95)\r\n";
-
- VAR
-
- mynewmenu : ARRAY 16 OF gt.NewMenu;
-
- (*------------------------------------*)
- PROCEDURE Init ();
-
- BEGIN (* Init *)
- (* Making the assumption that unitialised fields are zeroed... *)
-
- mynewmenu[0].type := gt.title;
- mynewmenu[0].label := SYS.ADR ("Project");
-
- mynewmenu[1].type := gt.item;
- mynewmenu[1].label := SYS.ADR ("Open...");
- mynewmenu[1].commKey := SYS.ADR ("O");
-
- mynewmenu[2].type := gt.item;
- mynewmenu[2].label := SYS.ADR ("Save");
- mynewmenu[2].commKey := SYS.ADR ("S");
-
- mynewmenu[3].type := gt.item;
- mynewmenu[3].label := gt.barLabel;
-
- mynewmenu[4].type := gt.item;
- mynewmenu[4].label := SYS.ADR ("Print");
-
- mynewmenu[5].type := gt.sub;
- mynewmenu[5].label := SYS.ADR ("Draft");
-
- mynewmenu[6].type := gt.sub;
- mynewmenu[6].label := SYS.ADR ("NLQ");
-
- mynewmenu[7].type := gt.item;
- mynewmenu[7].label := gt.barLabel;
-
- mynewmenu[8].type := gt.item;
- mynewmenu[8].label := SYS.ADR ("Quit...");
- mynewmenu[8].commKey := SYS.ADR ("Q");
-
- mynewmenu[9].type := gt.title;
- mynewmenu[9].label := SYS.ADR ("Edit");
-
- mynewmenu[10].type := gt.item;
- mynewmenu[10].label := SYS.ADR ("Cut");
- mynewmenu[10].commKey := SYS.ADR ("X");
-
- mynewmenu[11].type := gt.item;
- mynewmenu[11].label := SYS.ADR ("Copy");
- mynewmenu[11].commKey := SYS.ADR ("C");
-
- mynewmenu[12].type := gt.item;
- mynewmenu[12].label := SYS.ADR ("Paste");
- mynewmenu[12].commKey := SYS.ADR ("V");
-
- mynewmenu[13].type := gt.item;
- mynewmenu[13].label := gt.barLabel;
-
- mynewmenu[14].type := gt.item;
- mynewmenu[14].label := SYS.ADR ("Undo");
- mynewmenu[14].commKey := SYS.ADR ("Z");
-
- mynewmenu[15].type := gt.end;
- END Init;
-
- (*------------------------------------
- ** Watch the menus and wait for the user to select the close gadget
- ** or quit from the menus.
- *)
- PROCEDURE HandleWindowEvents (win : i.WindowPtr; menuStrip : i.MenuPtr);
-
- VAR
- msg : i.IntuiMessagePtr;
- done : BOOLEAN;
- menuNumber : INTEGER;
- menuNum : INTEGER;
- itemNum : INTEGER;
- subNum : INTEGER;
- item : i.MenuItemPtr;
- signals : SET;
-
- BEGIN (* HandleWindowEvents *)
- done := FALSE;
- WHILE ~done DO
- (* We only have one signal bit, so we do not have to check which
- ** bit broke the Wait().
- *)
- signals := e.Wait ({win.userPort.sigBit});
- LOOP
- IF done THEN EXIT END;
- msg := SYS.VAL (i.IntuiMessagePtr, e.GetMsg (win.userPort));
- IF msg = NIL THEN EXIT END;
- IF msg.class = {i.closeWindow} THEN
- done := TRUE
- ELSIF msg.class = {i.menuPick} THEN
- menuNumber := msg.code;
- WHILE (menuNumber # i.menuNull) & ~done DO
- item := i.ItemAddress (menuStrip^, menuNumber);
-
- (* Process the item here *)
- menuNum := i.MenuNum (menuNumber);
- itemNum := i.ItemNum (menuNumber);
- subNum := i.SubNum (menuNumber);
-
- (* stop if quit is selected *)
- IF (menuNum = 0) & (itemNum = 5) THEN
- done := TRUE
- END;
-
- menuNumber := item.nextSelect
- END
- END;
- e.ReplyMsg (msg)
- END
- END
- END HandleWindowEvents;
-
- (*------------------------------------*)
- PROCEDURE Main ();
-
- VAR
- win : i.WindowPtr;
- myVisualInfo : gt.VisualInfo;
- menuStrip : i.MenuPtr;
-
- BEGIN (* Main *)
- IF i.base.libNode.version >= 37 THEN
- ASSERT (gt.base # NIL, 100);
- win := i.OpenWindowTagsA
- ( NIL,
- i.waWidth, 400, i.waActivate, e.LTRUE,
- i.waHeight, 100, i.waCloseGadget, e.LTRUE,
- i.waTitle, SYS.ADR ("Menu Test Window"),
- i.waIDCMP, {i.closeWindow, i.menuPick},
- u.end );
- IF win # NIL THEN
- myVisualInfo := gt.GetVisualInfo (win.wScreen, u.end);
- IF myVisualInfo # NIL THEN
- menuStrip := gt.CreateMenus (mynewmenu, u.end);
- IF menuStrip # NIL THEN
- IF gt.LayoutMenus (menuStrip, myVisualInfo, u.end) THEN
- IF i.SetMenuStrip (win, menuStrip^) THEN
- HandleWindowEvents (win, menuStrip);
- i.ClearMenuStrip (win)
- END;
- gt.FreeMenus (menuStrip)
- END;
- END;
- i.CloseWindow (win)
- END;
- END;
- END;
- END Main;
-
- BEGIN (* GadToolsMenu *)
- Init ();
- Main ();
- END GadToolsMenu.
-